import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { OrderQueryService } from 'src/app/service/me/order-query.service';

@Component({
  selector: 'app-order-query',
  templateUrl: './order-query.component.html',
  styleUrls: ['./order-query.component.scss']
})
export class OrderQueryComponent implements OnInit {

  sourceDataState = [
    { value: '待受理', color: 'lime' },
    { value: '处理中', color: 'blue' },
    { value: '待评价', color: 'green' },
    { value: '已完成', color: 'cyan' },
    { value: '已退回', color: 'volcano' },
  ];
  progressState = [
    { key: 'sourceTime', title: '已申请' },
    { key: 'pendingDateTime', title: '待受理' },
    { key: 'processingDateTime', title: '已受理' },
    { key: 'evaluatingDateTime', title: '待评价' },
    { key: 'solvedDateTime', title: '已完成' },
    { key: 'backDateTime', title: '退回' },
  ]

  constructor(
    private orderQuery: OrderQueryService,
    private router: Router
  ) { }

  ngOnInit(): void {
    this.getOrderList()
  }

  data = []
  dataLoading = false
  cols = {
    'funcNo': '工单编号',
    'sourceDataTypeName': '工单类型',
    'sourceTime': '申请时间',
    'sourceDataState': '当前状态',
    '操作': '操作'
  }
  pageNumber = 1
  pageSize = 10
  total = 0
  getOrderList(){
    this.dataLoading = true
    this.data = []
    this.orderQuery._getOrderList(this.pageNumber, this.pageSize).subscribe({
      next: (res) => {
        console.log(res)
        if(res && res.resultList){
          this.data = res.resultList
          this.total = res.totalNumber
        }
        this.dataLoading = false
      },
      error: (error) => {
        this.dataLoading = false
      }
    })
  }
  	
  orderProgress(data: any){
    // this.router.navigate(['/me/order-progress'], { queryParams: { funcNo: data.funcNo } })
    this.progressModal = true
    this.getOrderProgress(data.funcNo)
  }	
  progressData: any = []
  getOrderProgress(funcNo: string){
    this.orderQuery._getOrderProgress(funcNo).subscribe({
      next: (res) => {
        console.log(res)
        if(res){
          let data: any = []
          this.progressState.forEach(item => {
            if(res[item.key]){
              data.push({ title: item.title, date: res[item.key] })
            }
          })
          this.progressData = data
        }
      },
      error: (error) => {
      }
    })
  }

  progressModal = false
  progressOnOk(){
    this.progressOnCancel()
  }
  progressOnCancel(){
    this.progressModal = false
  }
  

}
